<?php
/**
 * 点灯祈福模块微站定义
 *
 * @author junsion
 * @url http://s.we7.cc/index.php?c=store&a=author&uid=74516
 */
defined('IN_IA') or exit('Access Denied');
require_once IA_ROOT.'/addons/junsion_wxtools/func.php';
class junsion_wxtoolsModuleSite extends WeModuleSite {

	
	private function getAccessToken() {
		global $_W;
		load()->model('wxapp');
		$acid = $_W['acid'];
		if (empty($acid)) {
			$acid = $_W['uniacid'];
		}
		$account = WeAccount::create($acid);
		$token = $account->getAccessToken();
		return $token;
	}
	
	public function doWebMem() {
		//这个操作被定义用来呈现 管理中心导航菜单
		global $_W,$_GPC;
		
		$op = empty($_GPC['op'])?'display':$_GPC['op'];
		$weid = $_W['uniacid'];
		if($op == 'display'){
			$pindex = max(intval($_GPC['page']), 1);
			$psize = 20;
			$condition = "";
			if(!empty($_GPC['keyword'])){
				$condition .= " and nickname like '%{$_GPC['keyword']}%' ";
			}
			$limit = "limit " . (($pindex -1) * $psize).','. $psize;
			$list = pdo_fetchall('select * from ' . tablename($this->modulename.'_mem') . " where uniacid = '{$weid}' {$condition} order by id desc {$limit}");
			foreach ($list as &$value) {
				$value['num'] = col("select count(1) from ".tb('mcollect')." where mid='{$value['id']}' and status=1");
			}
			$total = pdo_fetchcolumn('select count(1) from ' . tablename($this->modulename.'_mem') . " where uniacid = '{$weid}' ");
			$pager = pagination($total, $pindex, $psize);
		}
		elseif ($op == 'del') {
			$id = $_GPC['id'];
			$item = pdo_fetch('select * from ' . tablename($this->modulename.'_mem') . " where id = '{$id}'");
			if(empty($item)){
				message('操作失败',$this->createWebUrl('mem'),'error');
			}
			if(pdo_delete($this->modulename.'_mem',array('id'=>$id)) === false) message('操作失败',referer(),'error');
			else message('操作成功',$this->createWebUrl('mem'),'success');
		}
		include $this->template('mem');
	}
	
	public function doWebScoreClear(){
		global $_W,$_GPC;
		pdo_query("update ".tablename('mc_members')." set credit1=0 where uniacid='{$_W['uniacid']}'");
		MSG('积分清零成功','referer');
	}
}
